<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * menu_ul()
 * Genera una lista desordenada con la clase current en el elemento seleccionado.
 */
if (!function_exists('loop_array')) {

    function loop_array($array = array(), $parent = 0) {
        $menu = "";
        if (!empty($array[$parent])) {
            $menu.="<ul>";
            foreach ($array[$parent] as $value) {
                $icon = isset($array[$value->id_menu]) > 0 ? 'clip-file-plus' : 'clip-file';
                $checked= $value->permiso==1? "checked='checked'": "";
                $menu.="<li style='list-style: none; cursor: pointer;'><div class='form-group form-inline'>";
                $menu.="<i class='" . $icon . "' id='icono" . $value->id_menu . "' onclick='abrirsubmenuPanel(" . $value->id_menu . ");' ></i>";
                $menu.="<label>";
                $menu.="<i class='icon-double-angle-right ' style='padding:5px'></i>";
                $menu.="<input type='checkbox' id='chk" . $value->id_menu . "' value='".$value->id_menu."' ".$checked.">";
                $menu.=" ".$value->desc_menu;
                $menu.="</label></div><div id='subpage" . $value->id_menu . "' style='display: none;'>";
                $menu.=loop_array($array, $value->id_menu);
                $menu.="</div></li>";
            }
            $menu.="</ul>";
            return $menu;
        }
    }

}

if (!function_exists('menu_permisos_ul')) {

    function menu_permisos_ul($data = array()) {
        foreach ($data as $row) {
            $array[$row->pagina_id][] = $row;
        }
        echo loop_array($array);
    }

}

if (!function_exists('loop_array2')) {

    function loop_array2($array = array(), $parent = 0) {
        $menu = "";
        if (!empty($array[$parent])) {
            $classul = $parent == 0 ? "class='main-navigation-menu'" : "class='sub-menu'";
            $menu.="<ul " . $classul . ">";
            foreach ($array[$parent] as $value) {
                $url = $value->url == 'javascript:;' ? $value->url : base_url("$value->url");
                $selected = isset($array[$value->id_menu]) > 0 ? "<i class='icon-arrow'></i>" : '';
                $icon = $parent == 0 ? "<i class='".$value->icono."'></i>" : '';
                $menu.="<li><a href='" . $url . "'>".$icon;
                $menu.="<span class='title'>".$value->desc_menu."</span>".$selected."</a>";
                $menu.=loop_array2($array, $value->id_menu);
                $menu.="</li>";
            }
            $menu.="</ul>";
            return $menu;
        }
    }

}

if (!function_exists('menu_principal')) {

    function menu_principal($data = array()) {
        foreach ($data as $row) {
            $array[$row->pagina_id][] = $row;
        }
        echo loop_array2($array);
    }

}
/* if (!function_exists('menu_ul')) {

  function menu_ul($data) {
  $menu = '<ul class="main_nav">' . "\n";
  foreach ($data as $item) {
  $menu .= '<li ><a href="#" >' . $item->desc_menu . '</a>';
  $menu .= '</li>' . "\n";
  }
  $menu .= '</ul>' . "\n";
  return $menu;
  }

  } */
?>
